<?php
/**
 * User: Allen
 * Date: 15-10-20
 * 设置限制
 */

class Lottery_set extends PC_Controller{
	
	public function __construct(){
		parent::__construct();
		$this->load->model('lottery_set_model');
		$this->load->model('code_model');
		$this->load->model('user_code_model');
	}
	
	/**
	 * @brief 获取抽奖设置
	 * @param Null
	 * @par 2015/10/20 Ver 1.00 Created by Allen
	 */
	public function set() {
		$this->data['data'] = $this->lottery_set_model->checkSet();		
		$this->load->view('/www/set_list.php',$this->data);
	}
		
	/**
	 * @brief 编辑抽奖设置
	 * @param Null
	 * @par 2015/10/20 Ver 1.00 Created by Allen
	 */
	public function edit() {
		$data = $_POST;
		$data['start_time'] = strtotime($data['start_time']);
		$data['end_time'] = strtotime($data['end_time']);
		$where['id'] = $data['id'];
		$edit_result = $this->lottery_set_model->editSet($where,$data);
		$go_url = "/www/lottery_set/set";
		if($edit_result){
			$this->location_href($this->lang->line('edit_success'),$go_url);			
		}else{
			$this->location_href($this->lang->line('edit_false'),$go_url);
		}
	}
	
	/**
	 * @brief 清空抽奖数据
	 * @param Null
	 * @par 2015/10/20 Ver 1.00 Created by Allen
	 */
	public function clear() {
		$code_data['status'] = 1;
		$code_where['status'] = 0;
		$user_where['id >'] = 0;
		$edit_code = $this->code_model->editCode($code_where,$code_data);
		$del_result = $this->user_code_model->deleteUsercode($user_where);
		$go_url = "/www/lottery_set/set";
		if($del_result){
			$this->location_href($this->lang->line('operate_success'),$go_url);
		}else{
			$this->location_href($this->lang->line('operate_false'),$go_url);
		}
	}	
}